package com.parking.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.parking.common.dao.impl.BaseDaoImpl;
import com.parking.dao.IParkingDao;
import com.parking.entity.FreeParking;
import com.parking.entity.Parking;

@Repository("parkingDao")
public class ParkingDaoImpl extends BaseDaoImpl<Parking, Integer> implements IParkingDao{

	private static Logger logger = Logger.getLogger(ParkingDaoImpl.class);
	
	@Override
	public List<Parking> findByKeywordAndAreacode(String keyword, int areacode, int pageSize,
			int pageNum) {
		String hql = "from Parking as parking where parking.name like :keyword and parking.areacode = :areacode order by parking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		return find(hql, params, pageSize, pageNum);
	}

	@Override
	public List<Parking> findByKeywordAndAreacode(String keyword, int areacode) {
		String hql = "from Parking as parking where parking.name like :keyword and parking.areacode = :areacode order by parking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		return find(hql, params);
	}

	@Override
	public long countByKeywordAndAreacode(String keyword, int areacode) {
		String hql = "select count(*) from Parking as parking where parking.name like :keyword and parking.areacode = :areacode order by parking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		return countAll(hql, params);
	}

}
